import { queryRule, addRule,removeRule,updateRule,getMatching,getGrouping,getValidating} from '@/services/bnsConfig/rule';

export default {
  namespace: 'rule',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryRule, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addRule, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
          if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeRule, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },

    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateRule, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },

    *matching({ payload, callback }, { call, put }) {
      const response = yield call(getMatching, payload);
      yield put({
        type: 'savematching',
        payload: response,
      });
      if (callback) callback(response);
    },
    *grouping({ payload, callback }, { call, put }) {
      const response = yield call(getGrouping, payload);
      yield put({
        type: 'savegrouping',
        payload: response,
      });
      if (callback) callback(response);
    },
    *validating({ payload, callback }, { call, put }) {
      const response = yield call(getValidating, payload);
      yield put({
        type: 'savevalidating',
        payload: response,
      });
      if (callback) callback(response);
    },   
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
